# -*- coding:utf-8 -*-
import logging
import redis
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import CSRFProtect
from flask_session import Session
from config import config, Config
from .utils.commons import RegexConverter
from logging.handlers import RotatingFileHandler
import pymysql
pymysql.install_as_MySQLdb()

# TODO 其他配置

# TODO 配置日志


def create_app(config_name):
    """创建flask应用app对象"""
    app = Flask(__name__)
    # TODO 补充


    # 为app中的url路由添加正则表达式匹配
    app.url_map.converters["regex"] = RegexConverter



    # 为app添加api蓝图应用
    from .api_1_0 import api as api_1_0_blueprint

    app.register_blueprint(api_1_0_blueprint, url_prefix="/api/v1.0")

    # 为app添加返回静态html的蓝图应用
    from .web_page import html as html_blueprint
    app.register_blueprint(html_blueprint)

    return app



